<%--
  Created by IntelliJ IDEA.
  User: zuxia
  Date: 2018/7/18
  Time: 11:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

<head>
    <meta charset="UTF-8">
    <title>菜品信息</title>
    <link rel="stylesheet" href="../css/amazeui.min.css" />
    <link rel="stylesheet" href="../css/layui.css" />

</head>

<body>
<div>
    <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf">
            <strong class="am-text-primary am-text-lg">菜品管理</strong>
        </div>
        <div class="am-u-sm-12 am-u-md-6">
            <div class="am-btn-toolbar">
                <div class="am-btn-group am-btn-group-xs">
                    <button type="button" class="am-btn am-btn-default">
                        <a href="addFood.jsp">新增</a>
                    </button>
                </div>
            </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3"></div>
        <div class="am-u-sm-12 am-u-md-3">
            <div class="am-input-group am-input-group-sm">
                <input id="sousuo" type="text" class="am-form-field" placeholder="请输入菜品名称">
                <span class="am-input-group-btn">
							<button class="am-btn am-btn-default" id="sousuobt" type="button">搜索</button>
				        </span>
            </div>
        </div>
    </div>

    <hr>

    <ul id="table_tbody" class='am-avg-sm-2 am-avg-md-4 am-avg-lg-6 am-margin gallery-list\' >

    </ul>
    <div id="mydiv" style="position: fixed ;bottom: 5px; align-content: center;margin-left: 39%;"  >

    </div>

</div>
</body>

<script type="text/javascript" src="../js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="../myplugs/js/plugs.js"></script>
<script type="text/javascript" src="../js/lay/dest/layui.all.js"></script>
<script type="text/javascript" src="../js/Popup.js"></script>

<script type="text/javascript" src="../js/jquery-1.4.1.js"></script>
<script type="text/javascript">
    //添加ajax分页
    $().ready(function() {
        //执行一次
        loaddata("","","12");

        //搜索单击事件
        $("#sousuobt").click(function(){
            var keyword = $("#sousuo").val();
            //console.log(keyword);
            // 加载数据
            loaddata(keyword,"","12");
        });
        //详情按钮单击事件
        // $("#showorder").live("click",function(){
        //     var orderid=$(this).parent().parent().prevAll().last().text();
        //     console.log(orderid+"111");
        //     window.location.href="/fullboy/skipvalue.action?skipvalue="+orderid.trim();
        // });
        //删除按钮单击事件
        $("#deleteFood").live("click",function(){
            var foodid=$(this).parent().parent().parent().prevAll().last().text();
            deleteFood(foodid);
            loaddata("","","12");
        });

        $(".prev").live("click", function(){
            var keyword = $("#sousuo").val();
            // 计算上一页的页码
            var pageNo = $(".current_num").text();
            pageNo = parseInt(pageNo);
            if(pageNo == undefined || pageNo <= 1){
                pageNo = 1;
            }else{
                pageNo = pageNo -1;
            }
            // 加载数据
            loaddata(keyword, pageNo,"12");
        });

        $(".next").live("click", function(){
            var keyword = $("#sousuo").val();
            // 计算下一页的页码
            var pageNo = $(".current_num").text();
            pageNo = parseInt(pageNo);
            var totalNo = $(".total_num").text();
            totalNo = parseInt(totalNo);
            if(pageNo == undefined){
                pageNo = 1;
            }else if(pageNo >= totalNo){
                pageNo =totalNo;
            }else{
                pageNo = pageNo + 1;
            }
            // 加载数据
            loaddata(keyword, pageNo,"12");
        });

        $(".first").live("click", function(){
            var keyword = $("#sousuo").val();
            // 计算下一页的页码
            var pageNo = 1;
            // 加载数据
            loaddata(keyword, pageNo,"12");
        });

        $(".last").live("click", function(){
            var keyword = $("#sousuo").val();
            // 计算下一页的页码
            var pageNo = $(".total_num").text();
            if(pageNo == undefined){
                pageNo = 1;
            }
            // 加载数据
            loaddata(keyword, pageNo,"12");
        });

    });

    //删除事件
    function deleteFood(typeid) {
        $.ajax({
            url:"/fullboy/deleteFood.action",
            data:{"foodid":foodid},
            type: "POST",
            cache: false,
        });
    }
    //ajax加载数据方法
    function loaddata(keyword,pageno,pagesize) {
        $("#table_tbody").empty();
        $("#mydiv").empty();
        $.ajax({
            url:"/fullboy/queryFood.action",
            data:{"keyword":keyword,"pageno":pageno,"pagesize":pagesize},
            type: "POST",
            cache: false,
            dataType: "json",
            success:function(data){
                console.log(data);
                if(data.success){
                    var foodlist=data.data.list;
                    for(var i=0;i<foodlist.length;i++){
                        var foodlistobj=foodlist[i];
                        $("#table_tbody").append("<li>"+
                        "<a href='javascript:void(0)' onclick='modifyFood('修改菜品',1)\'>"+
                        "<div class='gallery-title'>"+
                        "<center>"+
                        "<img class='am-img-thumbnail am-img-bdrs' id='"+foodlistobj.dId+"' style='width: 170px;height: 170px;' src='"+foodlistobj.dImg+"' alt='暂无图片'>"+
                        "<span>"+foodlistobj.dName+"</span>"+
                        "</center>"+
                        "</div>"+
                        "</a>"+
                        "</li>");
                    }

                    $("#mydiv").append("<br><tr style='border-bottom:1px solid #AAAAAA;height: 50px;text-align:center;'><td colspan='3'><div id='page_div'><span class='current_num'>" +
                        data.data.pageNo+"</span>/<span class='total_num'>"+data.data.pageCount+"</span>页   每页"+data.data.pageSize+"条  共"+
                        data.data.totalNumber+"条数据 "+
                        "&nbsp;&nbsp;<a href='javascript:void(0);' class='prev'>上一页</a>"+
                        "&nbsp;&nbsp;<a href='javascript:void(0);' class='next'>下一页</a>"+
                        "&nbsp;&nbsp;<a href='javascript:void(0);' class='first'>首页</a> "+
                        "&nbsp;&nbsp;<a href='javascript:void(0);' class='last'>尾页</a></div></td></tr>");
                }else{
                    $("#table_tbody").append("<tr><td colspan='3' style='color:#2530ff'>"+data.errorMessage+"</td></tr>");
                }
            }
        });
    }


</script>
</html>
